<?php
/**
 * @link https://gitee.com/toshcn/yii2-oauth2-server
 * @copyright Copyright (c) 2018 len168.com
 * @license https://gitee.com/toshcn/yii2-oauth2-server/blob/master/LICENSE
 */

namespace toshcn\yii2\oauth2server\controllers;

use toshcn\yii2\oauth2server\filters\ErrorToExceptionFilter;
use yii\helpers\ArrayHelper;
use yii\rest\Controller;

/**
 * Token controller for the `oauth2server` module
 */
class TokenController extends Controller
{
    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return ArrayHelper::merge(parent::behaviors(), [
            'exceptionFilter' => [
                'class' => ErrorToExceptionFilter::className()
            ],
        ]);
    }

    /**
     * @return mixed
     */
    public function actionIndex()
    {
        $response = $this->module->getServer()->handleTokenRequest();
        return $response->getParameters();
    }
}
